package com.croa.controller;

import com.croa.service.AdminService;
import com.dix.base.common.DataResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController("Admin.AdminController")
@RequestMapping("/admin/1/admin")
@Slf4j
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/login")
    public DataResponse login(@RequestParam("username") String username,
                              @RequestParam("password") String password) {
//        log.info(httpRequest.getURI().toString());
        HashMap result = adminService.login(username.trim(), password.trim());
        return DataResponse.create().putAll(result);
    }

    @PostMapping("/insert")
    public DataResponse insertAdmin(@RequestParam("username") String username,
                                    @RequestParam("password") String password,
                                    @RequestParam(value = "name", defaultValue = "") String name,
                                    @RequestParam(value = "department_id", defaultValue = "0") Long departmentId,
                                    @RequestParam(value = "role_id", defaultValue = "0") Long roleId) {
//        String adminId = userContext !!.userId;
//        adminService.insertAdmin(adminId, username.trim(), password.trim(), name.trim(), departmentId, roleId);
        return DataResponse.create();
    }
}
